home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0090_Direct Access I-O Ports.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  1.3 KB  |  53 lines

  1. {
  2. There have been several posts about _real-time_ port I/O under Windows.
  3. I've used the following scheme to control via I/O ports and tell the user what is going on via
  4. wav files.
  5.  
  6. {----------------------------------------}
  7. For port I/O under Delphi 1, use
  8.  
  9. var  i,j:word;
  10.  
  11.  port[i]:=j; {write to port i}
  12.  j:=port[i];  {read from port i}
  13.  
  14.   The sound stuff (see below) was not very satisfactory - either make async, and sometimes get 
  15. the end chopped off the sound when a second sound is started, or make sync and freeze activity 
  16. because you have to wait until the sound has played.
  17.  
  18. {----------------------------------------}
  19. Under Delphi 2.0 and Win95, for port I/O use something like:
  20.  
  21. procedure SetPort(address,value:Word);
  22. var bvalue:byte;
  23. begin
  24.    bvalue:=trunc(value and 255);
  25.    asm
  26.       mov dx,address
  27.       mov AL,bvalue
  28.       out DX,AL
  29.    end;
  30. end;
  31.  
  32. function GetPort(address:Word):Word;
  33. var bvalue:byte;
  34. begin
  35.    asm
  36.       mov dx,address
  37.       in aL,dx
  38.       mov bvalue,aL
  39.    end;
  40.    result:=bvalue;
  41. end;
  42.  
  43. and then 
  44. var i,j:word;
  45. begin
  46.    Setport(i,j);
  47.    j:=GetPort(i);
  48. end;
  49.  
  50. {----------------------------------------}
  51. Under Win NT, you have to use a Vxd for port I/O.
  52. See Dr. Dobbs Journal, Nov. 1995 for an exxample which contains no port I/O.
  53.